package leetcode_1000;

public class LongPressedName_925 {
	public static void main(String[] args) {
		LongPressedName_925 test=new LongPressedName_925();
		System.out.println(test.isLongPressedName("alex", "aaleex"));
		System.out.println(test.isLongPressedName("saeed", "ssaaedd"));
		System.out.println(test.isLongPressedName("leelee", "lleeelee"));
		System.out.println(test.isLongPressedName("laiden", "laiden"));
	}
	
	public boolean isLongPressedName(String name, String typed) {
		if(name.length()>typed.length())
			return false;
		if(name.length()==0) return false;
        char []s1=name.toCharArray();
        char []s2=typed.toCharArray();
        int before1,before2,index1=0,index2=0;
        while(index1<name.length()&&index2<typed.length()) {
        	before1=s1[index1];
        	before2=s2[index2];
        	if(before1!=before2)
        		return false;
        	int run1=index1,run2=index2;
        	while(run1<s1.length&&s1[run1]==before1) ++run1;
        	while(run2<s2.length&&s2[run2]==before2) ++run2;
        	if(run2-index2<run1-index1)
        		return false;
        	index1=run1;
        	index2=run2;
        }
        if(index1==name.length()&&index2==typed.length())
        	return true;
        return false;
    }
}
